package cn.xuanxuanyuhua.crm.web.controller;

import cn.xuanxuanyuhua.crm.domain.SystemDictionaryItem;
import cn.xuanxuanyuhua.crm.query.SystemDictionaryItemQueryObject;
import cn.xuanxuanyuhua.crm.service.ISystemDictionaryService;
import cn.xuanxuanyuhua.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/systemDictionaryItem")
public class SystemDictionaryItemController {

    @Autowired
    private ISystemDictionaryService service;

    @RequestMapping("/list")
    public String list(Model m,@ModelAttribute("qo")SystemDictionaryItemQueryObject qo){
        if(qo.getParentId() > 0){
            qo.setOrderBy("sequence desc");
            m.addAttribute("pageInfo",service.querySystemDictionaryItem(qo));
        }
        m.addAttribute("list",service.list());
        return "/systemDictionaryItem/list";
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(SystemDictionaryItem entity){
        service.saveOrUpdate(entity);
        return new JSONResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        service.deleteSystemDictionaryItem(id);
        return new JSONResult();
    }

}
